let api_url = 'http://localhost:3000'

function Http({ data = {}, url, type = 'get' }) { 

    let token  = localStorage.getItem('token')

    return new Promise((resolve, reject) => {

        $.ajax({
            url: api_url + url,
            data,
            type,
            headers:{
                authorization: token
            },
            success(res) { //成功的回调
                resolve({ err: null, result: res })
            },
            error(err) {//失败的回调
                resolve({ err: err })
            }
        })

    })
}

function qsToJson(query) {
    let obj = {}
    let s1 = query.substring(1) //name=admin&keyword=%E5%95%86%E5%9F%8E
    let arr1 = s1.split('&') //[ 'name=admin','keyword=%E5%95%86%E5%9F%8E' ]
    // console.log(arr1)
    arr1.forEach(value => {
        let arr2 = value.split('=')
        obj[arr2[0]] = decodeURIComponent( arr2[1] )  
    })
    return obj
}